package com.hbnu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbnu.system.config.BaseException;
import com.hbnu.system.mapper.ZxxkMapper;
import com.hbnu.system.model.entity.Zxxk;
import com.hbnu.system.service.ZxxkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 纵向学科类别(Zxxk)表服务实现类
 *
 * @author makejava
 * @since 2024-12-21 21:31:02
 */
@Service
public class ZxxkServiceImpl extends ServiceImpl<ZxxkMapper, Zxxk> implements ZxxkService {
    
    @Autowired
    private ZxxkService zxxkService;

    @Override
    public boolean addZxxk(Zxxk zxxk) {
        if(StrUtil.isEmpty(zxxk.getId()) || StrUtil.isBlank(zxxk.getId())){
            throw new BaseException("纵向学科出现错误，请重新输入");
        }
        return baseMapper.insert(zxxk) == 1;
    }

    @Override
    public boolean deleteZxxk(String ID) {
        Zxxk zxxk = baseMapper.selectOne(Wrappers.lambdaQuery(Zxxk.class)
                .eq(Zxxk::getId, ID));
        if (Objects.isNull(zxxk)){
            throw new BaseException("纵向学科有误");
        }

        return baseMapper.deleteById(ID) == 1;
    }

    @Override
    public boolean updateZxxk(Zxxk zxxk) {
        return false;
    }

    @Override
    public List<Zxxk> getOneZxxk() {
        // 创建一个LambdaQueryWrapper，不添加任何条件，即查询所有记录
        LambdaQueryWrapper<Zxxk> queryWrapper = new LambdaQueryWrapper<>();
        List<Zxxk> zxxks = baseMapper.selectList(queryWrapper);
        return zxxks;
    }
}

